	$(document).ready(function(){
		var getag = $('.pushdata input[name=getag]').val();
		var geteui = $('.pushdata input[name=geteui]').val();
		var getapply = $('.pushdata input[name=getapply]').val();
		$("li[role=presentation]").each(function(i){
			if(getag&&geteui&&getapply){
				if($(this).children().attr("aria-controls")==getapply){
					$("li[role=presentation]").attr('class','');
					$("li[role=presentation]").children().attr('aria-expanded','false');
					$(this).attr('class','active');
					$(this).children().attr('aria-expanded','true');
					$("#myTabContent").children().attr('class','tab-pane fade');
					$("#"+getapply).attr('class','tab-pane fade active in');
					$.ajax({
						type:"post",
						url:"/admin/device/toajax",
						data:{
							"ag":getag,
							"eui":geteui,
							"application":getapply
						},
						headers: {
							'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
			     		},
			     		success:function(str){
			     			$("#"+getapply).html(str);
			     		}
					});
				}
			}else{
				if($(this).children().attr("aria-expanded")=="true"){
					fun2(i);
				}
			}
			$(this).click(function(){
			fun2(i);
			});
		});
	});


	function fun2(i){
		var apply = $("li[role=presentation]:eq("+i+")").children().attr("aria-controls");
		$.ajax({
			type:"post",
			url:"/admin/device/toajax",
			data:{"application":apply},
			headers: {
				'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
     		},
     		success:function(str){
     			$("#"+apply).html(str);
     		}
		});
	}

	function fun(lg,app){
		var lw_page;
		var ag = $('#'+app+' select[name=ag] option:selected').val();
		var eui = $('#'+app+' input[name=eui]').val();
		var area = $('#'+app+' input[name=area]').val();
		var building = $('#'+app+' input[name=building]').val();
		var room = $('#'+app+' input[name=room]').val();
		// 判断如果是form表单提交
		if(lg=='submit'){
			lw_page =1;
		}else{
			lw_page = lg;
		}
		$.ajax({
			type:"post",
			url:"/admin/device/toajax",
			data:{
				"ag":ag,
				"eui":eui,
				"area":area,
				"building":building,
				"room":room,
				"page":lw_page,
				"application":app
			},
			headers:{
				'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
 		 	},
 		 	success:function(str){
 		 		$("#"+app).html(str);
 		 	}
		});
	}
	function del(id,app) {
        $.ajax({
            type:'post',
            url:'/admin/device/del',
            async:false,
            data:{
                'id':id,
				'application':app
            },
			headers:{
				'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
 		 	},
            dateType:'json',
            success:function (str) {
                var data = jQuery.parseJSON(str);
                if(data.status == '1'){
                    fun(1,app);
                }
                return false;
            }
        });
    }